//
//  TimeTableView.m
//  iMarks
//
//  Created by Christian Speich on 06.01.08.
//  Copyright 2008 Christian Speich. All rights reserved.
//

#import "TimeTableView.h"
#import "TimeTableDayView.h"
#import "SubjectsManager.h"

@implementation TimeTableView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
		navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UINavigationBar defaultSize].width, [UINavigationBar defaultSize].height)];
		transView = [[UITransitionView alloc] initWithFrame:CGRectMake(0.0f, [UINavigationBar defaultSize].height, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height)];
		
		[navigationBar setBarStyle:2];
		[navigationBar setDelegate:self];
		
		monday = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"monday", @"Monday")];
		mondayView = [[TimeTableDayView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height) forDay:@"Monday"];
		tuesday = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"tuesday", @"Tuesday")];
		tuesdayView = [[TimeTableDayView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height) forDay:@"Tuesday"];
		wednesday = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"wednesday", @"Wednesday")];
		wednesdayView = [[TimeTableDayView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height) forDay:@"Wednesday"];
		thursday = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"thursday", @"Thursday")];
		thursdayView = [[TimeTableDayView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height) forDay:@"Thursday"];
		friday = [[UINavigationItem alloc] initWithTitle:NSLocalizedString(@"friday", @"Friday")];
		fridayView = [[TimeTableDayView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height-[UINavigationBar defaultSize].height) forDay:@"Friday"];
		
		[navigationBar pushNavigationItem:monday];
		[navigationBar showLeftButton:nil withStyle:2 rightButton:NSLocalizedString(@"tuesday", @"Tuesday") withStyle:0];
		currentDay = @"Monday";

		[transView addSubview:mondayView];
		
		[self addSubview:transView];
		[self addSubview:navigationBar];
    }
    return self;
}

- (void)navigationBar:(UINavigationBar*)_bar buttonClicked:(int)button
{
	if (button == 0) {
		if ([currentDay isEqualToString:@"Monday"]) {
			[navigationBar pushNavigationItem:tuesday];
			[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"wednesday", @"Wednesday") leftBack:NO];
			currentDay = @"Tuesday";
			
			[transView transition:1 toView:tuesdayView];
		}
		else if ([currentDay isEqualToString:@"Tuesday"]) {
			[navigationBar pushNavigationItem:wednesday];
			[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"thursday", @"Thursday") leftBack:NO];
			currentDay = @"Wednesday";
			
			[transView transition:1 toView:wednesdayView];
		}
		else if ([currentDay isEqualToString:@"Wednesday"]) {
			[navigationBar pushNavigationItem:thursday];
			[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"friday", @"Friday") leftBack:NO];
			currentDay = @"Thursday";
			
			[transView transition:1 toView:thursdayView];
		}
		else if ([currentDay isEqualToString:@"Thursday"]) {
			[navigationBar pushNavigationItem:friday];
			[navigationBar showButtonsWithLeft:nil right:nil leftBack:NO];
			currentDay = @"Friday";
			
			[transView transition:1 toView:fridayView];
		}
		else {
			NSLog(@"to from %@", currentDay);
		}
	}
}

- (void) navigationBar:(UINavigationBar*)_bar poppedItem:(UINavigationItem*)item
{
	if ([currentDay isEqualToString:@"Tuesday"]) {
		[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"tuesday", @"Tuesday") leftBack:NO];
		currentDay = @"Monday";
		
		[transView transition:2 toView:mondayView];
	}
	else if ([currentDay isEqualToString:@"Wednesday"]) {
		[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"wednesday", @"Wednesday") leftBack:NO];
		currentDay = @"Tuesday";
		
		[transView transition:2 toView:tuesdayView];
	}
	else if ([currentDay isEqualToString:@"Thursday"]) {
		[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"thursday", @"Thursday") leftBack:NO];
		currentDay = @"Wednesday";
		
		[transView transition:2 toView:wednesdayView];
	}
	else if ([currentDay isEqualToString:@"Friday"]) {
		[navigationBar showButtonsWithLeft:nil right:NSLocalizedString(@"friday", @"Friday") leftBack:NO];
		currentDay = @"Thursday";
		
		[transView transition:2 toView:thursdayView];
	} else {
		NSLog(@"back from %@", currentDay);
	}

}

@end
